const loadUtils = require('loader-utils')
function loader(buffer){
  console.log("文件数据大小：(字节)", buffer.byteLength);
  // console.log( this.getOptions())
  var { limit = 1000, filename = "[contenthash].[ext]" } = this.getOptions();
  // base64 格式
  let content;
  if (buffer.byteLength >= limit) {
    content = getFilePath.call(this ,buffer, filename);
  }else{
    content = getbase64(buffer)
  }
  
  // console.log(filename)
  
  // console.log(content)
  // console.log(content)
  // 
  return `module.exports=\`${content}\``
}
loader.raw = true  // 该loader 要处理的是原始数据
module.exports = loader

function getbase64 (buffer){
    return "data:image/png;base64," + buffer.toString('base64')
}

function getFilePath(buffer, name) {
  let filename = loadUtils.interpolateName(this, `assets/`+name, {
    content: buffer
});
// console.log(filename)
this.emitFile(filename, buffer);
return filename;
}